//
//  BPBaseTool.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/8/5.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "BPBaseTool.h"
#import "BPhttpTool.h"
#import "MJExtension.h"

@implementation BPBaseTool

+ (void)getWithUrl:(NSString *)url param:(id)param resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    NSDictionary *params = [param keyValues];
    
    [BPhttpTool get:url params:params success:^(id responseObj) {
        if (success) {
            id result = nil;
            if ([responseObj isKindOfClass:[NSArray class]]) {
                //假如是数组格式
                result = [resultClass objectArrayWithKeyValuesArray:responseObj];
            }else{
                //假如是字典格式
                result = [resultClass objectWithKeyValues:responseObj];
            }
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)postWithUrl:(NSString *)url param:(id)param resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    NSDictionary *params = [param keyValues];
    [BPhttpTool post:url params:params success:^(id responseObj) {
        if (success) {
            id result = nil;
            if ([responseObj isKindOfClass:[NSArray class]]) {
                 result = [resultClass objectArrayWithKeyValuesArray:responseObj];
            }else{
                 result = [resultClass objectWithKeyValues:responseObj];
            }
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

@end
